function exportCSV([switch]$export,$inputString) {
    if ($export) {
        $inputString | Export-Csv -Path "output.csv" -NoTypeInformation
    } else {
        $inputString
    }
}

exportCSV  true "Hello World"
exportCSV false "Hello PowerShell"